import type { App } from "vue";
import { defineStore, createPinia } from "pinia";
import type { AdminIdTto } from "../type";

// 注册全局的 pinia
export function setupStore(app: App<Element>) {
    app.use(createPinia());
}

export const useAdminStore = defineStore("admin", {
    state: (): AdminIdTto => {
        return {
            adminId: 0, // 0 表示null
            account: "",
            adminName: "",
            phone: "",
            roleName: ""
        }
    },
    getters: {
        getAdminName(): string {
            return this.adminName;
        }
    },
    actions: {
        setAdmin(admin: AdminIdTto) {
            this.adminId = admin.adminId;
            this.account = admin.account;
            this.adminName = admin.adminName;
            this.phone = admin.phone;
            this.roleName = admin.roleName;
            // 将 数据存储到 cookie 中
        },
    }
})

